-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable colours on GitHub Actions by default #7462
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me, especially since we handle some special cases there already anyways (e.g. disabling markup with Jython on Windows).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
BTW the java condition is no longer needed as we don't support Jython (Python2 only AFAIK), so can remove it as well if you feel like it.
src/_pytest/_io/terminalwriter.py
Outdated
@@ -32,7 +32,7 @@ def should_do_markup(file: TextIO) -> bool: | |||
and file.isatty() | |||
and os.environ.get("TERM") != "dumb" | |||
and not (sys.platform.startswith("java") and os._name == "nt") | |||
) | |||
) or os.environ.get("GITHUB_ACTIONS") == "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be a little clearer as a separate if
before the return
(can leave as is if you prefer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea, since we then handle all the special cases before the "ordinary" one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved!
src/_pytest/_io/terminalwriter.py
Outdated
@@ -32,7 +32,7 @@ def should_do_markup(file: TextIO) -> bool: | |||
and file.isatty() | |||
and os.environ.get("TERM") != "dumb" | |||
and not (sys.platform.startswith("java") and os._name == "nt") | |||
) | |||
) or os.environ.get("GITHUB_ACTIONS") == "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea, since we then handle all the special cases before the "ordinary" one.
src/_pytest/_io/terminalwriter.py
Outdated
@@ -32,7 +32,7 @@ def should_do_markup(file: TextIO) -> bool: | |||
and file.isatty() | |||
and os.environ.get("TERM") != "dumb" | |||
and not (sys.platform.startswith("java") and os._name == "nt") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me to remove this if we don't support Jython anymore - looks like it was originally added in pytest-dev/py@536252c some 10 years ago 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I'm actually -1 on this. the environment variable doesn't tell whether or not you're piped or other possible things where color is inappropriate and it's extremely special cased for github actions
But if you are piped you don't get a Your point about being specific is correct, but if we can get this correct in all cases I still see it as a win as every user will get this for free without additional configuration. |
right, but if you're running in github actions, you can't discern whether that output is going to the log or is being piped into something else since both cases would be ( |
This is a valid concern I'm afraid... and I can't think of any way to find out whether we're writing to a pipe/file or to the standard output on GitHub Actions. On the other hand, I wonder how common the case of someone piping pytest output somewhere on GitHub Actions would be. Alternatively, maybe this should go into some |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, but if you're running in github actions, you can't discern whether that output is going to the log or is being piped into something else since both cases would be (GITHUB_ACTIONS present, no tty)
Ahh got it, while running in GitHub actions we never have an tty, because we are being piped, of course. Thanks for the clarification.
In that case I agree we should probably turn down this PR.
Perhaps we should add a blurb somewhere in the docs mentioning --color=yes
when running in CI services such as GHA, Travis, AppVeyor, etc? I don't think we have anything in that sense currently.
I think this is only a problem with GHA, as others somehow provide a fake TTY. FWIW I ended up using this at the top of the workflow file: env:
PY_COLORS: "1" that way, colors will be enabled for both pytest and tox, and it won't influence other places where commandline arguments are passed or handled. |
Let's close this for now, thanks @hugovk for giving it a go anyway! 👍 |
Sure, no problem! |
@The-Compiler, we are already doing that in https://github.com/ghdl/ghdl-cosim/blob/master/test.py#L25-L30. See output: https://github.com/ghdl/ghdl-cosim/runs/854521453?check_suite_focus=true#step:4:13. Unfortunately, there is an annoyance which I could not solve: when pytest is used to execute makefiles, everything is correct; but when executing other python scripts, the output/log is empty. Compare https://github.com/ghdl/ghdl-cosim/runs/854521453?check_suite_focus=true#step:4:174 and any other of the "Log" collapsible groups. That's the reason that has prevented me from "announcing" the solution; which is really simple and effective otherwise. |
@umarcor Interesting! I have no idea why that is. FWIW what I'd be interested in is a solution collapsing the output of pytest's own test failure output. |
All you need to do is print |
Note you're using an old/alternative/depecated? syntax there, that should probably be |
Yes, you are correct. It's an old, probably deprecated, syntax. Sorry about that. I'll fix it on my side. |
Workaround to fix #7443.
GitHub Actions doesn't provide a tty, so many tools that normally output in colour instead output in monochrome: actions/runner#241.
GitHub say it's low in their backlog and they have no plans to fix it (actions/runner#241 (comment)), so instead of requiring every pytest user to explicitly force colours for pytest, improve the pytest colour detection using the
GITHUB_ACTIONS
env var:https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
Test using this branch: